/*******************************************************************************
 * Copyright 2011 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.badlogic.gdx.scenes.scene2d.ui;

import java.util.ArrayList;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.BitmapFont.HAlignment;
import com.badlogic.gdx.graphics.g2d.BitmapFont.TextBounds;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Button.ButtonStyle;
import com.badlogic.gdx.scenes.scene2d.ui.tablelayout.Cell;

/**
 * A button with text on it.
 * 
 * <h2>Functionality</h2>
 * A button can be either in a pressed or unpressed state. A {@link ClickListener} can
 * be registered with the Button which will be called in case the button was clicked/touched.
 * 
 * <h2>Layout</h2>
 * The (preferred) width and height of a Button are derrived from the border patches in the
 * background {@link NinePatch} as well as the bounding box around the multi-line text displayed
 * on the Button. Use {@link Button#setPrefSize(int, int)} to programmatically change the size
 * to your liking. In case the width and height you set are to small for the contained text you
 * will see artifacts.
 * 
 * <h2>Style</h2>
 * A Button is a {@link Widget} displaying a background {@link NinePatch} as well as
 * multi-line text with a specific font and color. The style is defined via an instance
 * of {@link ButtonStyle}, which can be either done programmatically or via a {@link Skin}.</p>
 * 
 * A Button's style definition in a skin XML file should look like this:
 * 
 * <pre>
 * {@code 
 * <button name="styleName" 
 *         down="downNinePatch" 
 *         up="upNinePatch" 
 *         font="fontName" 
 *         fontColor="colorName"/>/>
 * }
 * </pre>
 * 
 * <ul>
 * <li>The <code>name</code> attribute defines the name of the style which you can later use with {@link Skin#newButton(String, String, String)}.</li>
 * <li>The <code>down</code> attribute references a {@link NinePatch} by name, to be used as the button's background when it is pressed</li>
 * <li>The <code>up</code> attribute references a {@link NinePatch} by name, to be used as the button's background when it is not pressed</li>
 * <li>The <code>font</code> attribute references a {@link BitmapFont} by name, to be used to render the text on the button</li>
 * <li>The <code>fontColor</code> attribute references a {@link Color} by name, to be used to render the text on the button</li>
 * </ul> 
 * 
 * @author mzechner
 *
 */
public class nButton extends Button {

	public nButton(String name, String label, ButtonStyle style) {
		super(name, label, style);
	}		
	
	public boolean touchDown(float x, float y, int pointer) {
		if (this.visible)
			return super.touchDown(x, y, pointer);
		else
		return false;
	}
	
	
	public boolean touchUp(float x, float y, int pointer) {
		if (this.visible)
			return super.touchUp(x, y, pointer);
		else
		return false;
	}
	
	ArrayList<Cell> cells = new ArrayList<Cell>();
	java.util.List<Actor> actors;
	float oldPrefWidth;
	float oldPrefHeight;
	public void Show(Boolean show) {
		if (show && !visible) {
			this.cells.addAll(cells);
			this.visible = true;
			prefWidth = oldPrefWidth;
			prefHeight = oldPrefHeight;
			if (this.parent instanceof Container) {
				Cell i =((Container) this.parent).layout.getCell(this);
				i.ignore = !i.ignore;
				
			}
		}
		else if (!show && visible) {
				cells = (ArrayList<Cell>) this.cells.clone();
				this.visible = false;
				
				this.cells.clear();
				oldPrefWidth = prefWidth;
				oldPrefHeight = prefHeight;
				prefWidth = 0;
				prefHeight = 0;
				if (this.parent instanceof Container) {
					Cell i =((Container) this.parent).layout.getCell(this);
					i.ignore = !i.ignore;
					
				}
		}
		
	}
	
	
}
